<template>
  <div id="cluereport">
    <el-dialog
      title="变更内容"
      :visible.sync="dialogVisible"
      width="1200px" :close-on-click-modal="false" :close-on-press-escape="false">
      <section class="wboxd" style="width:1140px">
        <el-table :data="logdetails" highlight-current-row border v-loading="detailsLoading" empty-text='无变更'
          >
          <el-table-column prop="field" label="字段名称">
          </el-table-column>
          <el-table-column prop="before" label="变更前" width="430">
            <template slot-scope="scope">
              <div v-if="scope.row.field==='处理处分类型'">
                <div v-for="(item,index) in cllxDic" :key="index" style="clear:both">
                  <div v-if="scope.row.before&&scope.row.before!==''&&scope.row.before.indexOf(item.value)>-1">
                    <div style="font-size:var(--size14) !important;display:block;float:left;font-weight:bolder">{{item.label}}：</div>
                    <div style="font-size:var(--size14) !important;display:block;float:left;padding-left:10px" v-for="(it,idx) in item.children" :key="idx" v-show="scope.row.before.split(',').indexOf(it.value)>-1">{{it.label}}</div>
                    <!-- <div style="font-size:var(--size14) !important;display:block;float:left;" v-if="item.value==='0901'&&scope.row.before.split(',').indexOf('090105')>-1"></div>
                    <div style="font-size:var(--size14) !important;display:block;float:left;" v-if="item.value==='0902'&&scope.row.before.split(',').indexOf('090206')>-1"></div> -->
                    <div style="font-size:var(--size14) !important;display:block;float:left;" v-if="item.value==='0905'&&scope.row.before.split(',').indexOf('0905')>-1"></div>
                  </div>
                </div>
              </div>
              <div v-else-if="scope.row.field==='处理类型其他'" v-html="formatQtcllx(scope.row.before)">
              </div>
              <!-- <div v-else-if="scope.row.field==='问题来源'" v-html="code2Label(scope.row.before,wtlyDic)">
              </div>
              <div v-else-if="scope.row.field==='处理决定机关'" v-html="code2Label(scope.row.before,cljdjgDic)">
              </div>
              <div v-else-if="scope.row.field==='影响期'" v-html="code2Label(scope.row.before,yxqDic)">
              </div> -->
              <div v-else v-html="scope.row.before"></div>
            </template>
          </el-table-column>
          <el-table-column prop="after" label="变更后" width="430">
            <template slot-scope="scope">
              <div v-if="scope.row.field==='处理处分类型'">
                <div v-for="(item,index) in cllxDic" :key="index" style="clear:both">
                  <div v-if="scope.row.after&&scope.row.after!==''&&scope.row.after.indexOf(item.value)>-1">
                    <div style="font-size:var(--size14) !important;display:block;float:left;font-weight:bolder">{{item.label}}：</div>
                    <div style="font-size:var(--size14) !important;display:block;float:left;padding-left:10px" v-for="(it,idx) in item.children" :key="idx" v-show="scope.row.after.split(',').indexOf(it.value)>-1">{{it.label}}</div>
                    <!-- <div style="font-size:var(--size14) !important;display:block;float:left;" v-if="item.value==='0901'&&scope.row.after.split(',').indexOf('090105')>-1"></div>
                    <div style="font-size:var(--size14) !important;display:block;float:left;" v-if="item.value==='0902'&&scope.row.after.split(',').indexOf('090206')>-1"></div> -->
                    <div style="font-size:var(--size14) !important;display:block;float:left;" v-if="item.value==='0905'&&scope.row.after.split(',').indexOf('0905')>-1"></div>
                  </div>
                </div>
              </div>
              <div v-else-if="scope.row.field==='处理类型其他'" v-html="formatQtcllx(scope.row.after)">
              </div>
              <!-- <div v-else-if="scope.row.field==='问题来源'" v-html="code2Label(scope.row.after,wtlyDic)">
              </div>
              <div v-else-if="scope.row.field==='处理决定机关'" v-html="code2Label(scope.row.after,cljdjgDic)">
              </div>
              <div v-else-if="scope.row.field==='影响期'" v-html="code2Label(scope.row.after,yxqDic)">
              </div> -->
              <div v-else v-html="scope.row.after"></div>
            </template>
          </el-table-column>
        </el-table>
      </section>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item>干部监督</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/cadrehandling' }">干部处理</el-breadcrumb-item>
      <el-breadcrumb-item>操作日志</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxd">
    <!--工具条-->
      <h1>干部处理 操作日志</h1>
      <!--列表-->
      <el-table :data="list" highlight-current-row v-loading="listLoading" style="width: 100%;" :height="tableHeight" border
        >
        <el-table-column type="index" label="序号" width="80" fixed align="center" class-name="tableth">
        </el-table-column>
        <el-table-column prop="operateType" label="操作类型" width="200">
          <template slot-scope="scope">
            {{operateTypeName(scope.row.operateType)}}
          </template>
        </el-table-column>
        <el-table-column prop="operateUserName" label="操作用户" width="200">
        </el-table-column>
        <el-table-column prop="dataCreateDatetime" label="操作时间">
        </el-table-column>
        <el-table-column label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="primary" @click="detail(scope.row.id)" style="margin:10px 0">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination style="float:right" :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  data () {
    return {
      cllxDic: [],
      wtlyDic: [],
      cljdjgDic: [],
      yxqDic: [],
      detailsLoading: false,
      logdetails: [],
      dialogVisible: false,
      listLoading: false,
      tableHeight: 100,
      list: [],
      pageNum: 1,
      pageSize: 20,
      totalnum: 0,
      keys: [
        {key: 'source', name: '来源'},
        {key: 'source', name: '来源'}
      ]
    }
  },
  methods: {
    code2Label (str, dic) {
      for (let item of dic) {
        if (item.value === str) {
          return item.label
        }
      }
    },
    formatQtcllx (str) {
      if (str && str !== '') {
        let obj = JSON.parse(str)
        let html = ''
        for (let key in obj) {
        //   if (key === '090105') {
        //     html = html + '其他管理手段：' + obj[key] + '<br>'
        //   } else if (key === '090206') {
        //     html = html + '其他组织处理或组织调整：' + obj[key] + '<br>'
        //   } else if (key === '0905') {
          html = html + '其他：' + obj[key] + '<br>'
        // }
        }
        return html
      } else {
        return str
      }
    },
    formatObj (obj) {
      if (obj) {
        if (typeof obj === 'string') {
          return obj
        } else {
          let str = ''
          for (let i = 0; i < obj.length; i++) {
            str = str + `单位：${obj[i].unit} 姓名：${obj[i].name}(${obj[i].idCardNo}) 职务：${obj[i].job}<br>`
          }
          return str
        }
      }
    },
    operateTypeName (id) {
      switch (id) {
        case 1:
          return '新增'
        case 2:
          return '修改'
        case 3:
          return '删除'
      }
    },
    detail (id) {
      this.dialogVisible = true
      this.detailsLoading = true
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/busClueReportProcessLog/getComparison?id=${id}`)
        .then(response => {
          this.detailsLoading = false
          if (response.data.success) {
            this.logdetails = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.detailsLoading = false
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getList()
      }
    },
    getList () {
      let para = {
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }
      this.listLoading = true
      // var personParams = { Page: 0, Pagenum: 20, Personname: '', Unitkey: '', Sortkey: '', Isace: true, timestamp: new Date().getTime() }
      this.$http
        .post(this.$http.defaults.selectionAPI + `api/busClueReportProcessLog/queryLog`, para)
        .then(response => {
          if (response.data.success) {
            this.listLoading = false
            this.list = response.data.result.records
            this.totalnum = response.data.result.total
            this.changeSizeFlag = false
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    getDics (code) {
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/sysDict/getByCode?code=` + code)
        .then(response => {
          if (response.data.success) {
            switch (code) {
              case '08':
                this.wtlyDic = response.data.result
                break
              case '09':
                this.cllxDic = response.data.result
                break
              case '10':
                this.cljdjgDic = response.data.result
                break
              case '11':
                this.yxqDic = response.data.result
                break
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    getAllDics () {
      this.getDics('08')
      this.getDics('09')
      this.getDics('10')
      this.getDics('11')
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 220
      })
    }
  },
  mounted () {
    this.getAllDics()
    this.getList()
    this.tableresize(this)
    window.onresize = () => {
      this.tableresize(this)
    }
  }
}
</script>
<style>
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #testlist .wboxs{
    height:45px;
    padding-top:10px;
  }
</style>
<style scoped>
  #cluereport .el-button{
    color:#fff !important;
  }
  #cluereport h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  #cluereport .wboxs{
    width: 100%;
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
    padding:0;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
